package leetcode_401_500;

import com.sun.org.apache.bcel.internal.generic.RET;

import java.util.Arrays;

public class LeeCode_416 {
    public static void main(String[] args) {
        System.out.println(canPartition(new int[]{1, 2, 5}));
    }
    private static boolean canPartition(int[] nums) {
        int sum = Arrays.stream(nums).sum();
        if (sum % 2 == 1)
            return false;
        int target = sum / 2;
        int[] dp = new int[target + 1];
        dp[0] = 1;
        for (int num : nums) {
            for(int i = target; i > num; i--){
                dp[i] += dp[i - num];
            }
        }
        return dp[target] != 0;
    }
}
